#include "playericon.h"

PlayerIcon::PlayerIcon(Player* p)
{
    static int homex=354;
    static int homey=549;
    static int firstx=516;
    static int firsty=368;
    static int secondx=354;
    static int secondy=207;
    static int thirdx=179;
    static int thirdy= 368;

    myPlayer=p;
    setFlag(QGraphicsItem::ItemIsMovable, true);
    this->setX(homex);
    this->setY(homey);
}

void PlayerIcon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
           QWidget *widget)
{
    QColor* backgroundColor= new QColor(70,130,180);//blue
    QColor* fontColor= new QColor(255,255,255);//white
    painter->setPen(backgroundColor->toRgb());
    painter->drawRect(boundingRect());
    painter->fillRect(boundingRect(), backgroundColor->toRgb());
    painter->setPen(fontColor->toRgb());
    painter->drawText(0,0,myPlayer->getLastName());
    painter->drawText(0,70,QString::number(myPlayer->getJerseyNumber()));
}

// Define the bounding rectangle of the object for collision detection
QRectF  PlayerIcon::boundingRect() const
{
    return QRectF(-75,-75,150,150);
}

Player* PlayerIcon::getPlayer(){
    return myPlayer;
}
